<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>档案管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <jsp:include page="/inc/head.jsp" flush="true"/>
    <link rel="stylesheet" href="${basePath }/css/bootstrapValidator.min.css">
    <style type="text/css">
        .error-tip {
            font-size:12px;
            padding-top: 7px;
            margin-bottom: 0;
            text-align: left;
            display:none;
            color:#ff0000;
        }
        .has-error .form-control {
            border-color:#ff0000;
        }
        .form-control {
            background-color:transparent!important;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini" style="padding:20px 10px;">
<div class="container-fluid" style="background-color: #607d8b">
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 600px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改密码</h4>
            </div>
            <div class="modal-body">
                <form id="volumeForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator" method="post">

                    <div class="form-group" >
                        <label for="oldPassword" class="col-sm-2 control-label">旧密码</label>
                        <div class="col-sm-6">
                            <input type="password" name="oldPassword" class="form-control" id="oldPassword">
                        </div>
                        <div class="col-sm-4 error-tip" id="oldUserPasswordError" >
                            密码错误
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="password" class="col-sm-2 control-label">新密码</label>
                        <div class="col-sm-6">
                            <input type="password" class="form-control" name="password" id="password" >
                        </div>
                        <div class="col-sm-4 error-tip" id="userpasswordError" >
                            密码需大于6位,且只能为数字或英文字母
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="repassword" class="col-sm-2 control-label">确认密码</label>
                        <div class="col-sm-6">
                            <input type="password" class="form-control" id="repassword" name="repassword">
                        </div>
                        <div class="col-sm-4 error-tip" id="userpassword1Error" >
                            两次密码不一致
                        </div>
                    </div>

                </form>



                <!--



                 <form id="volumeForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator" method="post">
                     <table style="width: 100%" id="editPasswordTable">
                         <tr>
                             <td class="content" style="width: 10px">
                                 旧&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码:
                             </td>
                             <td class="content">
                                 <input type="password" id='oldPassword' name='oldPassword'   placeholder="必填项" value=''/>
                             </td>
                             <td id="oldUserPasswordError" height="35"  class="content" style="display:none">
                                 <font color="red" size="-1">密码错误</font>
                             </td>
                         </tr>
                         <tr>
                             <td class="content" style="width: 10px">
                                 新&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码:
                             </td>
                             <td class="content">
                                 <input type="password" id='password' name='password'   placeholder="必填项" value=''/>
                             </td>
                             <td id="userpasswordError" height="35"  class="content" style="display:none">
                                 <font color="red" size="-1">密码需大于6位,且只能为数字或英文字母</font>
                             </td>
                         </tr>
                         <tr>
                             <td class="content">
                                 确&nbsp;认&nbsp;密&nbsp;码:
                             </td>
                             <td class="content">
                                 <input type="password" id='repassword' name='repassword'   placeholder="必填项" value=''/>
                             </td>
                             <td id="userpassword1Error" height="35" class="content" style="display:none">
                                 <font color="red" size="-1">两次密码不一致</font>
                             </td>
                         </tr>
                     </table>
                     <div class="modal-footer">
                         <button type="button" onclick="cancleToMainPage()" class="btn btn-default" data-dismiss="modal">关闭</button>
                         <button type="button" onclick="editPasswordSubmit()" class="btn btn-primary">确认修改</button>
                     </div>
                 </form> -->



            </div>
            <div class="modal-footer">
                <button type="button" onclick="cancleToMainPage()" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="editPasswordSubmit()" class="btn btn-primary">确认修改</button>
            </div>
        </div>
    </div><!-- /.modal -->
</div>
<jsp:include page="/inc/footer.jsp" flush="true"/>
<script src="${basePath }/assets/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script>
    var sign;
    var mark;
    var flag;
    $(function () {
        $("#myModal").modal("show");
        sign="0";
        mark="0";
        flag="0";


    });
    //密码修改
    function editPasswordSubmit() {
        var password = $("#password").val();
        var repassword = $("#repassword").val();
        if(sign=="1"&&mark=="1"&&flag=="1"&&password==repassword){
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/newPassword",
                data: {newPassword:password},
                success: function (data) {
                    if (data=="1") {
                        $("#myModal").modal("hide");
                        if(confirm("修改成功,请重新登录！3秒后自动跳转")){
                            //点击确定后操作
                            <%--window.top.location.href = "${pageContext.request.contextPath }/pcwindow/logoutSystemJump";--%>
                            $.ajax({
                                url:"${basePath }/pcwindow/logoutSystemJump",
                                type:"get",
                                async :false,
                                success:function (data) {
                                    if(data=="1"){
                                        window.top.location.href = "/login";
                                    }
                                }

                            })
                        }
                        setTimeout(function() {
                            <%--window.top.location.href = "${pageContext.request.contextPath }/pcwindow/logoutSystemJump";--%>
                            $.ajax({
                                url:"${basePath }/pcwindow/logoutSystemJump",
                                type:"get",
                                async :false,
                                success:function (data) {
                                    if(data=="1"){
                                        window.top.location.href = "/login";
                                    }
                                }

                            })
                        }, 3000);
                    }else{
                        alert("修改密码失败，请稍后再试")
                    }
                },
            });
        }else{
            alert("请确认输入是否正确！")
        }
    }

    //oldPassword验证
    $("#oldPassword").focus(function() {
        $("#oldPassword").css("background-color", "#DCE9F5");
    });
    $("#oldPassword").blur(function(){
        var oldPwd = $("#oldPassword").val();
        $("#assword").css("background-color", "white");
        $.ajax({
            url:"${basePath }/pcwindow/verifyPassword",
            type:"post",
            data:{passWord:oldPwd},
            async:false,
            success:function (data) {
                console.log(data)
                if(data=="1"){
                    sign="1";
                    $("#oldUserPasswordError").hide().prev().removeClass('has-error').addClass('has-success');

                }else{
                    sign="0";
                    $("#oldUserPasswordError").show().prev().removeClass('has-success').addClass('has-error');
                }
            }
        })
    });

        //password验证
        $("#password").focus(function() {
            $("#password").css("background-color", "#DCE9F5");
        });
        $("#password").blur(function(){
            var upassword = $("#password").val();
            $("#assword").css("background-color", "white");
            if (upassword.length >= 6 ) {
                var re;
                re =  /^[\da-z]+$/;
                if (re.test(upassword)) {
                    mark="1"
                    $("#userpasswordError").hide().prev().removeClass('has-error').addClass('has-success');
                }else{
                    mark="0"
                    $("#userpasswordError").show().prev().removeClass('has-success').addClass('has-error');
                }
            } else {
                mark="0"
                $("#userpasswordError").show().prev().removeClass('has-success').addClass('has-error');
            }

        });


        //password1验证
        $("#repassword").focus(function() {
            $("#repassword").css("background-color", "#DCE9F5");
        });
        $("#repassword").blur(function(){
            var password = $("#password").val();
            var repassword = $("#repassword").val();
            $("#repassword").css("background-color", "white");
            if (repassword != password) {
                flag="0";
                $("#userpassword1Error").show().prev().removeClass('has-success').addClass('has-error');
            } else {
                flag="1";
                $("#userpassword1Error").hide().prev().removeClass('has-error').addClass('has-success');
            }
        });

    /**
     * 修改模态框关闭后跳转至主页
     * wr
      */
    function cancleToMainPage(){
        $("#password").val("");
        $("#repassword").val("");
        $("#myModal").modal('hide');
        window.location.href = "${basePath }/pcwindow/modifiedPasswordOut";
    }


    //关闭事件
    $(function () {
            $("#myModal").on('hide.bs.modal', function () {
                $("#password").val("");
                $("#repassword").val("");
                window.location.href = "${basePath }/pcwindow/modifiedPasswordOut";
            })
    });
</script>
</body>
</html>

